package it.koutifaris.testforclassutils;

public class SamePackageAssert {

	private static final StackTraceHelper stackTraceHelper = new StackTraceHelper(SamePackageAssert.class.getPackage());

	public static void assertSamePackage(Class<?> classUnderTest, Class<?> testClass) {
		assertEquals(classUnderTest.getPackage().getName(), testClass.getPackage().getName());
	}

	public static void assertSamePackage(Class<?> classUnderTest) {
		assertSamePackage(classUnderTest, getCallingClass());
	}

	private static Class<?> getCallingClass() {
		return stackTraceHelper.getCallingClass();
	}

	private static void assertEquals(String pkgUnderTestName, String testPkgName) {
		if (!pkgUnderTestName.equals(testPkgName)) {
			throw new NotSamePackageException(pkgUnderTestName, testPkgName);
		}
	}

}
